Hi, I would like to define in a dxl file loaded in the startup a virtual fonction. No problem with that.
The problem is I want to define the concrete function in standard dxl file (i.e. launched normally from a DOORS session).
The problem is I cannot define the int global variable to store the function address in the dxl file loaded in the startup…
Any idea. jaracic - Tue May 30 04:15:40 EDT 2017 |
Re: How to virtualize in startup Lets see if I understand this correctly: - you want to have a virtual function inside the startup file? - you want to define the concrete implementation of this function during a later DXL execution? This is possible, but has the problem that after the later DXL execution ends, the callback you set will not be valid anymore. Additionally each callback that you call from a different DXL context will have a different stack, therefore all global variables of DXL Context 1 will not be available in DXL Context 2. Therefore you would need to restrict that function only to access variables that are guarateed to exist in the calling context. If you need more details, post back. Regards, Mathias
|
Re: How to virtualize in startup Mathias Mamsch - Tue May 30 08:42:14 EDT 2017 Lets see if I understand this correctly: - you want to have a virtual function inside the startup file? - you want to define the concrete implementation of this function during a later DXL execution? This is possible, but has the problem that after the later DXL execution ends, the callback you set will not be valid anymore. Additionally each callback that you call from a different DXL context will have a different stack, therefore all global variables of DXL Context 1 will not be available in DXL Context 2. Therefore you would need to restrict that function only to access variables that are guarateed to exist in the calling context. If you need more details, post back. Regards, Mathias
Hi Mathias, I think I understand. but I don't know how to :
and Actually it why I also posted that : https://www.ibm.com/developerworks/community/forums/html/topic?id=e03af595-1e69-4f92-b8d9-84ecf31fea50#repliesPg=0
Thank for your always valuable help. Joseph. |
Re: How to virtualize in startup jaracic - Thu Jun 01 03:38:30 EDT 2017 Hi Mathias, I think I understand. but I don't know how to :
and Actually it why I also posted that : https://www.ibm.com/developerworks/community/forums/html/topic?id=e03af595-1e69-4f92-b8d9-84ecf31fea50#repliesPg=0
Thank for your always valuable help. Joseph. Ok lets first get down to the most simple example. Creating a virtual function on global level (e.g. from the startups). First execute the following code in DXL interaction to install the global virtual function:
evalTop_ "
int gadFunc = 0;
void setFunc ( void func(int) ) {
gadFunc = (addr_ func) int;
}
int BGlobal = 123;
void callFuncProxy ( void func(int), int x) {
if (gadFunc == 0) error \"No function has been set!\";
func(x);
}
void callFunc (int x) {
callFuncProxy (addr_ gadFunc, x);
}
void someUtilityFunction(int z) {
print \"Utilities! Value of BGlobal: \" BGlobal \"\\n\";
callFunc (z + 5);
}
"
Then clear the DXL edit window and put in the following code:
void myFunc (int x) {
print "Yeah! Go Client!" x "\n";
}
setFunc (myFunc); // set virtual function implementation inside the child context
someUtilityFunction(99); // call global function that uses virtual function
You should see, everything is working so far. When we use the global DXL context the someUtility function can safely access the value of "BGlobal" since the child context shares with the parent context the stack. This would probably also be true for eval_ invocations. This would NOT work if someUtilityFunction was inside a waiting context (e.g. GUI or attribute DXL), since the reference of BGlobal would point to somewhere in the other context. Does this help you so far? It breaks down of course when you try to execute someUtilityFunction again without setting the function before. The value from the old execution is still stored put points to nirvana. Regards, Mathias |
Re: How to virtualize in startup Mathias Mamsch - Thu Jun 01 04:39:13 EDT 2017 Ok lets first get down to the most simple example. Creating a virtual function on global level (e.g. from the startups). First execute the following code in DXL interaction to install the global virtual function:
evalTop_ "
int gadFunc = 0;
void setFunc ( void func(int) ) {
gadFunc = (addr_ func) int;
}
int BGlobal = 123;
void callFuncProxy ( void func(int), int x) {
if (gadFunc == 0) error \"No function has been set!\";
func(x);
}
void callFunc (int x) {
callFuncProxy (addr_ gadFunc, x);
}
void someUtilityFunction(int z) {
print \"Utilities! Value of BGlobal: \" BGlobal \"\\n\";
callFunc (z + 5);
}
"
Then clear the DXL edit window and put in the following code:
void myFunc (int x) {
print "Yeah! Go Client!" x "\n";
}
setFunc (myFunc); // set virtual function implementation inside the child context
someUtilityFunction(99); // call global function that uses virtual function
You should see, everything is working so far. When we use the global DXL context the someUtility function can safely access the value of "BGlobal" since the child context shares with the parent context the stack. This would probably also be true for eval_ invocations. This would NOT work if someUtilityFunction was inside a waiting context (e.g. GUI or attribute DXL), since the reference of BGlobal would point to somewhere in the other context. Does this help you so far? It breaks down of course when you try to execute someUtilityFunction again without setting the function before. The value from the old execution is still stored put points to nirvana. Regards, Mathias Hi Mathias, No problem with the principle... Thanks anyway
It it exactly what I said in https://www.ibm.com/developerworks/community/forums/html/topic?id=e03af595-1e69-4f92-b8d9-84ecf31fea50 when I was talking about "...in parrallel...).
It is why gadFunc int variable cannot be defined in the top level, and it is why I would like to "virtualize" the access of the gadFunc variable. My idea was to define in the top level a Skip list to store addresses:
evalTop_ "
Skip gadFuncList = createString;
void setFunc ( void func(int), string DXL_ExecID) {
int gadFunc = (addr_ func) int;
delete(gadFuncList, DXL_ExecID)
put(gadFuncList, DXL_ExecID, gadFunc)
}
void callFuncProxy ( void func(int), string DXL_ExecID, int param) {
int gadFunc = 0
find(gadFuncList, DXL_ExecID, gadFunc)
if (gadFunc == 0) error \"No function has been set!\";
func(param);
}
void callFunc (string DXL_ExecID, int param) {
int gadFunc = 0
find(gadFuncList, DXL_ExecID, gadFunc)
callFuncProxy (addr_ gadFunc, DXL_ExecID, param);
}
void someUtilityFunction(string DXL_ExecID, int z) {
callFunc (DXL_ExecID, z);
}
"
and in the the standard dxl context :
string DXL_ExecID = "??a unique ID (at least within the DOORS session) representing the whole DXL Execution??" //I don't know how to produce such a value
void myFunc (int x) {
print "Yeah! Go Client!" x "\n";
}
setFunc (myFunc, DXL_ExecID); // set virtual function implementation inside the child context
someUtilityFunction(DXL_ExecID, 99); // call global function that uses virtual function
If I'm able to get a unique ID representing the whole execution of the script, I can call the virtual function in different GUI.
OK : Now, how to get such a unique ID : see https://www.ibm.com/developerworks/community/forums/html/topic?id=e03af595-1e69-4f92-b8d9-84ecf31fea50
Is it clear? Regards. Joseph |
Re: How to virtualize in startup jaracic - Thu Jun 01 09:35:51 EDT 2017 Hi Mathias, No problem with the principle... Thanks anyway
It it exactly what I said in https://www.ibm.com/developerworks/community/forums/html/topic?id=e03af595-1e69-4f92-b8d9-84ecf31fea50 when I was talking about "...in parrallel...).
It is why gadFunc int variable cannot be defined in the top level, and it is why I would like to "virtualize" the access of the gadFunc variable. My idea was to define in the top level a Skip list to store addresses:
evalTop_ "
Skip gadFuncList = createString;
void setFunc ( void func(int), string DXL_ExecID) {
int gadFunc = (addr_ func) int;
delete(gadFuncList, DXL_ExecID)
put(gadFuncList, DXL_ExecID, gadFunc)
}
void callFuncProxy ( void func(int), string DXL_ExecID, int param) {
int gadFunc = 0
find(gadFuncList, DXL_ExecID, gadFunc)
if (gadFunc == 0) error \"No function has been set!\";
func(param);
}
void callFunc (string DXL_ExecID, int param) {
int gadFunc = 0
find(gadFuncList, DXL_ExecID, gadFunc)
callFuncProxy (addr_ gadFunc, DXL_ExecID, param);
}
void someUtilityFunction(string DXL_ExecID, int z) {
callFunc (DXL_ExecID, z);
}
"
and in the the standard dxl context :
string DXL_ExecID = "??a unique ID (at least within the DOORS session) representing the whole DXL Execution??" //I don't know how to produce such a value
void myFunc (int x) {
print "Yeah! Go Client!" x "\n";
}
setFunc (myFunc, DXL_ExecID); // set virtual function implementation inside the child context
someUtilityFunction(DXL_ExecID, 99); // call global function that uses virtual function
If I'm able to get a unique ID representing the whole execution of the script, I can call the virtual function in different GUI.
OK : Now, how to get such a unique ID : see https://www.ibm.com/developerworks/community/forums/html/topic?id=e03af595-1e69-4f92-b8d9-84ecf31fea50
Is it clear? Regards. Joseph In this case I would simply have the setFunc() function return a counter, which serves as an ID:
// global context
int giSetFuncCounter = 0;
int setFunc ( void func(int)) {
int gadFunc = (addr_ func) int;
delete(gadFuncList, DXL_ExecID)
put(gadFuncList, ++giSetFuncCounter, gadFunc)
return giSetFuncCounter; // return ID
}
which would then serve as an ID ... Inside the local context you can then have a library:
int localID = 0;
void setFuncLocal ( void func(int) ) {
localID = setFunc(func); // get ID from global context
}
void someUtilityFunction(int z) {
someUtilityFunction(z, localID);
}
To abstract the ID away from the client DXL, which is not too bad. Still leaves the question: why? ;-) Regards, Mathias |
Re: How to virtualize in startup Mathias Mamsch - Thu Jun 01 09:49:01 EDT 2017 In this case I would simply have the setFunc() function return a counter, which serves as an ID:
// global context
int giSetFuncCounter = 0;
int setFunc ( void func(int)) {
int gadFunc = (addr_ func) int;
delete(gadFuncList, DXL_ExecID)
put(gadFuncList, ++giSetFuncCounter, gadFunc)
return giSetFuncCounter; // return ID
}
which would then serve as an ID ... Inside the local context you can then have a library:
int localID = 0;
void setFuncLocal ( void func(int) ) {
localID = setFunc(func); // get ID from global context
}
void someUtilityFunction(int z) {
someUtilityFunction(z, localID);
}
To abstract the ID away from the client DXL, which is not too bad. Still leaves the question: why? ;-) Regards, Mathias Thank you Matthias, It almost fits my need... but only almost... I'll try to be more concrete (but also simple) to illustrate my need, and may be you'll understand why I ask for that In global context (startup) I would like to load theses dxl files in this order:
in virtual_ctx.inc, I need to have a virtual function that returns a unique ID representing the DXL execution context :
int getMyContextID() {
//the code.
}
in the log.inc I need to have a logIt(string) function:
Skip allLogs = create
void logIt_(string msgToLog, int inContext) {
//I get the right Buffer, thanks to inContext index
Buffer b = null
if (find(allLogs(inContext, b))) {
b += msgToLog
}
}
void logIt(string msgToLog) {
logIt_(msgToLog, getMyContext())
}
In functionalLayer1.inc and functionalLayer2.inc file I have a lot of functions that use logIt(string) function.
In two local contexts (in two gui loops for example) I would like these 2 dxl files loaded (in this order):
The concrete_ctx.inc file is aimed to define all I need to make concrete the int getMyContext() function (your counter technique suits me)
The prog.inc file contains a lot of call of functions in functionalLayer1.inc and functionalLayer2.inc files as well as a lot of functions that call directly logIt(string) function in log.inc
I cannot (don't want) use your proposed technique because It means I would have to add an additional parameter in a lot of functions ! For the moment I would like to not consider that... maintenance issues... I really hope it is more clear. Thank you Matthias for your advices. |
Re: How to virtualize in startup jaracic - Fri Jun 16 11:42:56 EDT 2017 Thank you Matthias, It almost fits my need... but only almost... I'll try to be more concrete (but also simple) to illustrate my need, and may be you'll understand why I ask for that In global context (startup) I would like to load theses dxl files in this order:
in virtual_ctx.inc, I need to have a virtual function that returns a unique ID representing the DXL execution context :
int getMyContextID() {
//the code.
}
in the log.inc I need to have a logIt(string) function:
Skip allLogs = create
void logIt_(string msgToLog, int inContext) {
//I get the right Buffer, thanks to inContext index
Buffer b = null
if (find(allLogs(inContext, b))) {
b += msgToLog
}
}
void logIt(string msgToLog) {
logIt_(msgToLog, getMyContext())
}
In functionalLayer1.inc and functionalLayer2.inc file I have a lot of functions that use logIt(string) function.
In two local contexts (in two gui loops for example) I would like these 2 dxl files loaded (in this order):
The concrete_ctx.inc file is aimed to define all I need to make concrete the int getMyContext() function (your counter technique suits me)
The prog.inc file contains a lot of call of functions in functionalLayer1.inc and functionalLayer2.inc files as well as a lot of functions that call directly logIt(string) function in log.inc
I cannot (don't want) use your proposed technique because It means I would have to add an additional parameter in a lot of functions ! For the moment I would like to not consider that... maintenance issues... I really hope it is more clear. Thank you Matthias for your advices. I think I understand what you want. You want to local and the global context accessing the log(string) function, but without introducing the necessary parameter that will tell the global context, to which (of possible many) DXL contexts to log. Not easy. One thing is clear - you cannot use a DXL variable to store the information, since the DXL variable of the child contexts are unknown to the global context. You would exactly as you say need a "DXL context ID", that is bound to the currently running DXL instance, which you can access from the global DXL context, but that is different, depending on from which child context it is called. So you could use anything local to the current DXL context, the DXL context pointer, the allocated objects list, etc. but the problem with all of these is, that they are memory addresses that might be reused later, thus inviting the same kind of crashes again, that we tried to avoid by introducing a skip list to store the function pointers alltogether. I think it would now be the time to think thoroughly about the requirements - Do you really need multiple child contexts at the same time to log into different logs? E.g. a GUI in "show" mode logging into a different file, than a currently running DXL script? If this is not the case you can get away MUCH simpler. Regards, Mathias. |
Re: How to virtualize in startup Mathias Mamsch - Fri Jun 16 14:25:41 EDT 2017 I think I understand what you want. You want to local and the global context accessing the log(string) function, but without introducing the necessary parameter that will tell the global context, to which (of possible many) DXL contexts to log. Not easy. One thing is clear - you cannot use a DXL variable to store the information, since the DXL variable of the child contexts are unknown to the global context. You would exactly as you say need a "DXL context ID", that is bound to the currently running DXL instance, which you can access from the global DXL context, but that is different, depending on from which child context it is called. So you could use anything local to the current DXL context, the DXL context pointer, the allocated objects list, etc. but the problem with all of these is, that they are memory addresses that might be reused later, thus inviting the same kind of crashes again, that we tried to avoid by introducing a skip list to store the function pointers alltogether. I think it would now be the time to think thoroughly about the requirements - Do you really need multiple child contexts at the same time to log into different logs? E.g. a GUI in "show" mode logging into a different file, than a currently running DXL script? If this is not the case you can get away MUCH simpler. Regards, Mathias.
Yes it is the need... unfortunately. Now since we need to store the function address that returns the context ID (of the current dxl context), I don't know how to virtualize this function in top level context (for all other functions to virualize it is OK since I (would) have a id-actually the context id- used as key in skips to store adresses of concrete functions.) May be the only solution if to add this additional parameter in ALL functions. grrr.... The perfect solution would be to access to an internal DXL perm that would return such a DXL context (unique) ID... your opinion Matthias ? Thanks. |
Re: How to virtualize in startup jaracic - Mon Jun 19 09:20:59 EDT 2017
Yes it is the need... unfortunately. Now since we need to store the function address that returns the context ID (of the current dxl context), I don't know how to virtualize this function in top level context (for all other functions to virualize it is OK since I (would) have a id-actually the context id- used as key in skips to store adresses of concrete functions.) May be the only solution if to add this additional parameter in ALL functions. grrr.... The perfect solution would be to access to an internal DXL perm that would return such a DXL context (unique) ID... your opinion Matthias ? Thanks. No such perm or ID ... The only thing that comes close to this is the dxlHere() command giving you a traceback with the last line (or the line before) being the root / entry point of the script. Using this you could get a "script" based log, that would also not change inbetween different calls of the script. But that means: Same GUI, Same log code. Note that even having such an ID would not be a perfect solution: Using the "count" appraoch from layout DXL your global skip will fill up in notime, making things slower and slower (dxlHere might come to rescue if it fits your requirements, you need to try). This root of this problem is that you want to put code to the global context, which I would definitely advise against. The only argument I heard for putting code on the global context is loading time of the scripts. There are other ways to reduce loading times. What is your reason for having these libraries on the global context? Having the logging code on the local context would totally void the problem. Regards, Mathias |
Re: How to virtualize in startup Mathias Mamsch - Mon Jun 19 09:59:17 EDT 2017 No such perm or ID ... The only thing that comes close to this is the dxlHere() command giving you a traceback with the last line (or the line before) being the root / entry point of the script. Using this you could get a "script" based log, that would also not change inbetween different calls of the script. But that means: Same GUI, Same log code. Note that even having such an ID would not be a perfect solution: Using the "count" appraoch from layout DXL your global skip will fill up in notime, making things slower and slower (dxlHere might come to rescue if it fits your requirements, you need to try). This root of this problem is that you want to put code to the global context, which I would definitely advise against. The only argument I heard for putting code on the global context is loading time of the scripts. There are other ways to reduce loading times. What is your reason for having these libraries on the global context? Having the logging code on the local context would totally void the problem. Regards, Mathias By the way - using a script based log code (dependent on the executed script file) you can extract the filename from the dxlHere ... The global context could simply try to eval_ a DXL file depending on the script files name. E.g. have a directory containing files: - log_link_creator_v1.dxl - log_requirement_type_attrDxl.dxl - ... The log function could simply:
void log (string s) {
string scriptName = getScriptFromDXLHere();
noError(); eval_ "#include <mylogdir/log_" scriptName ">"; lastError();
}
Using an approach like this, you can add / remove logging code at runtime. If this becomes to slow you can add buffering. Maybe this would also be an option? Regards, Mathias |
Re: How to virtualize in startup
Yes the reason of putting these dxl files in the global context is to improve performance of some dxl layouts and also the use of eval_ functions to isolate string table expansion due to (highly) repetitive XML RPC calls. The problem is the decision of putting these dxl file in global context came very later. The global design is not adapted... I have to pay this technical debt I'm afraid sonner than expected... I'm very interested to know about other techniques to reduce loading times. Except this last point, I think I have enough information to take a decision on my add-on. Thank you Mathias. Kind regards Joseph.
|